//Add a number to array and if there is carry increase array size. 
//---------------------------------------------------------------------- 
//For example input = {7,3,5,3,9} convert this to number 73539, add 1 so it becomes 73540 and convert to array {7,3,5,4,0}. 
//Array can be of any length, so you can't always represent array in form of in-built number format. So you have to do this summation in-place. Also, how would you increase array size in-case input = {9,9,9} so output = (1,0,0,0} 
//
//Assume, all elements of arrays are between 0 and 9.
#include <iostream>
#include <string>
#include <sstream>
#include <queue>
int * array_increment(int a[], int& size, int num) {
	for ( int i = size-1; i >= 0 && num != 0; --i ) {
		a[i] += num;
		if(a[i]>9) {
			a[i] %= 10;
			num = 1;
		}
		else {
			num = 0;
		}
	}
	if(num>0) {
		int * b = new int[size+1];
		b[0] = num;
		for(int i = 0; i < size; ++i) {
			b[i+1] = a[i];
		}
		size++;
		return b;
	}
	else 
		return a;
}

void test_array_increment() {
	int n;
	std::queue<int> q;
	std::cout << "enter the sequence of int:\n";
	std::string str;
	std::getline(std::cin,str);
	std::istringstream sstr(str);
	while (sstr >> n)
		q.push(n);
	int size = q.size();
	int * a = new int[size];
	for ( int i = 0; i < size; i++ ) {
		a[i] = q.front();
		q.pop();
	}
	std::cout << "enter the number to be added\n";
	std::cin >> n;
	int * result = array_increment(a,size,n);
	for ( int i = 0; i < size; i++ ) 
		std::cout << result[i];
	std::cout << std::endl;
}